<template>
  <div class="app-container">
<!--表单查询-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="姓名">
        <el-input v-model="authorQuery.name" placeholder="姓名"></el-input>
      </el-form-item>
      <el-form-item label="级别">
        <el-select v-model="authorQuery.level" clearable placeholder="级别">
          <el-option label="普通作者" value="1"></el-option>
          <el-option label="特约作者" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始">
        <el-date-picker
          v-model="authorQuery.begin"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="结束">
        <el-date-picker
          v-model="authorQuery.end"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择截止时间">
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="getAuthorList()">查询</el-button>
        <el-button type="default" @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">  <!--通过scope拿到绑定的数据-->
        {{scope.$index+1}}  <!--当前页的下标-->
        </template>
      </el-table-column>
      <el-table-column label="名称" prop="name" width="100" />
      <el-table-column label="级别" width="100">
        <template slot-scope="scope">
          {{scope.row.level===1?"普通创作者":"特约创作者"}}   <!--拿到每一行的数据-->
        </template>
      </el-table-column>
      <el-table-column label="创作者简介" prop="intro"  />
      <el-table-column label="工作经历" prop="career"  />
      <el-table-column label="添加时间" prop="gmtCreate"  width="160"/>
      <el-table-column label="排序" prop="sort"  width="60" />
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope  ">
          <!--修改的跳转  让其跳转到路由当中 编辑路由 页面和添加的是一样， 编辑当中是有参数
             在定义一个编辑的路由 router-link相当于a标签
         -->
          <router-link  :to="'/author/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteAuthorWithId(scope.row.id)">删除</el-button>
        </template>

      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      style="padding: 30px 0; text-align: center"
      background

      :current-page="page"
      :page-size="limit"
      layout="total, prev, pager, next, jumper"
      :hide-on-single-page="true"
      @current-change="getAuthorList"
      :total="total">
    </el-pagination>
  </div>
</template>


<script>
  import author from '@/api/video/author'

  export default {
    name: 'list',
    data() {
      return {
        list: null,
        page: 1,
        limit:10,
        total:0,
        authorQuery:{}
      }
    },
    created() {
      this.getAuthorList()
    },
    methods: {
      getAuthorList(page=1) {
        this.page = page
        author.getAuthorList(this.page,this.limit,this.authorQuery).then(
          response=>{
            console.log(response);
            this.list=response.data.rows;
            this.total=response.data.total;
          }
        );
      },
      deleteAuthorWithId(id){
        this.$confirm('此操作将永久删除该作者, 是否继续?', '提示', {

          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          author. deleteAuthorWithId(id).then(
            response=>{
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.getAuthorList(1);
            }
          )

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      },
      resetData(){/*清空查询的数据*/
      this.authorQuery = {} //清空表单
      //重新查询
      this.getAuthorList()
     }
    }
  }
</script>

<style scoped>

</style>
